<template>
    <div style="margin-top: 20px;padding:20px;background: white">

        <a-row v-show="!formVisible" :gutter="32" type="flex" justify="center">

            <span v-for="item in searchItems">

                <a-col :span="12">
                    <a-row :gutter="32">
                        <a-col :span="13">
                            {{item.name}}
                        </a-col>
                        <a-col :span="9">
                               <a-select v-model="searchMap[item.key]" style="width: 150px" default-value="-1"
                               >
                                    <a-select-option v-for="val in item.options" :selected="val.value==='-1'"
                                                     :value=val.value>{{val.text}}
                                    </a-select-option>

                             </a-select>
                        </a-col>


                    </a-row>

                </a-col>
            </span>

        </a-row>

        <a-button v-if="!formVisible" style="margin-bottom: 20px" type="primary" @click="addCoupon(null)"
                  class="editable-add-btn">
            发布优惠券
        </a-button>
        <div class="formTip" style="color: #E4393C">优惠券结束或手动结束后用户无法继续领取，但已经领取的优惠券可以在时间范围内继续适用</div>

        <a-button v-if="formVisible" style="margin-bottom: 20px" type="primary" @click="formVisible=false"
                  class="editable-add-btn">
            返回
        </a-button>
        <a-table
                v-show="!formVisible"
                :pagination="false"
                rowKey="id"
                size="middle" :columns="columns" :data-source="tableData" :scroll="{ x: 800, y: 500 }">
                <span slot="who" slot-scope="text, record">
                    <a-tag color="green">{{record.who===1?'通用券':record.who===2?'新人领取':record.who===3?'首单优惠':record.who===4?'会员优惠':'未知券'}}</a-tag>
                </span>
            <span slot="what" slot-scope="text, record">
                    <a-tag :color="record.what==1?'green':'orange'">{{record.what===1?'满减':record.what===2?'立减':'未知券'}}</a-tag>
            </span>
            <span slot="use_type" slot-scope="text, record">
                    <a-tag :color="record.useType==1?'blue':'orange'">{{record.useType===1?'指定期限':record.useType===2?'限时使用':'未知券'}}</a-tag>
            </span>
            <span slot="type" slot-scope="text, record">
                    <a-tag :color="record.type==1?'blue':'orange'">{{record.type===1?'店铺优惠':record.type===2?'系统优惠':'未知券'}}</a-tag>
            </span>
            <span slot="limit" slot-scope="text, record">
                    {{record.limit?record.limit:'无'}}
            </span>
            <span slot="createTime" slot-scope="text, record">
                    {{record.createTime?moment(record.createTime).format('YYYY-MM-DD HH:mm:ss'):'无'}}
            </span>
            <span slot="startTime" slot-scope="text, record">
                    {{record.startTime?moment(record.startTime).format('YYYY-MM-DD HH:mm:ss'):'无'}}
            </span>
            <span slot="endTime" slot-scope="text, record">
                    {{record.endTime?moment(record.endTime).format('YYYY-MM-DD HH:mm:ss'):'无'}}
            </span>


            <span slot="status" slot-scope="text, record">
                    <a-tag :color="record.deleted===0?'green':record.deleted===1?'red':''">{{record.deleted===0?'正常':'已结束'}}</a-tag>
            </span>

            <div slot="action" slot-scope="text,record">

                <a-button icon="edit" @click="addCoupon(record)"/>
                <a-divider type="vertical"></a-divider>
                <a-popconfirm
                        title="确定结束发行该优惠券吗?"
                        ok-text="确定"
                        cancel-text="取消"
                        @confirm="deleteCoupon(record,1)"
                >
                    <a-button style="color: red">结束</a-button>
                </a-popconfirm>
                <a-divider type="vertical"></a-divider>

                <a-button @click="deleteCoupon(record,0)">恢复</a-button>
            </div>

        </a-table>
        <a-pagination
                v-show="!formVisible"
                style="margin: 20px;float: right"
                v-model="pageMap.current"
                :page-size-options="pageSizeOptions"
                :total="pageMap.total"
                show-size-changer
                :page-size="pageMap.pageSize"
                @change="pageChange"
                @showSizeChange="onShowSizeChange"
        >
            <template slot="buildOptionText" slot-scope="props">
                <span>{{ props.value }}条/页</span>
            </template>
        </a-pagination>
        <div style="horiz-align: center;margin-left: 100px">
            <a-card v-show="formVisible" style="padding: 0px 20px;width: 75%;overflow: auto">
                <a-form-model
                        hide-required-mark
                        ref="couponForm"
                        :model="couponForm"
                        :rules="couponFormRules"
                >
                    <a-row :gutter="[24,0]">
                        <a-form-model-item prop="id" hidden>
                            <a-input
                                    v-model="couponForm.id"
                            />
                        </a-form-model-item>
                        <a-col :span="12">
                            <a-form-model-item label="优惠券名" prop="name">
                                <a-input
                                        v-model="couponForm.name"
                                />
                            </a-form-model-item>
                        </a-col>

                        <a-col :span="12">
                            <a-form-model-item label="描述" prop="desc">
                                <a-input
                                        v-model="couponForm.desc"
                                />
                            </a-form-model-item>
                        </a-col>

                    </a-row>
                    <a-row :gutter="[24,0]">
                        <a-col :span="12">
                            <a-form-model-item label="使用群体" prop="who">
                                <a-select v-model="couponForm.who" placeholder="请选择使用群体">
                                    <a-select-option value="1">
                                        通用券
                                    </a-select-option>
                                </a-select>
                            </a-form-model-item>
                        </a-col>
                        <a-col :span="12">
                            <a-form-model-item label="领取方式" prop="order">
                                <a-select v-model="couponForm.how" placeholder="领取方式">
                                    <a-select-option value="1">
                                        手动领取
                                    </a-select-option>
                                </a-select>
                            </a-form-model-item>
                        </a-col>
                    </a-row>
                    <a-row :gutter="[24,0]">
                        <a-col :span="12">
                            <a-form-model-item label="优惠金额" prop="discountPrice">
                                <a-input-number style="width: 100%;" v-model="couponForm.discountPrice" :min="0"
                                                step="0.01"></a-input-number>
                                <span class="formTip">请输入1/2/3/5及5的整数倍金额，面额不得超过1000元</span>
                            </a-form-model-item>

                        </a-col>
                        <a-col :span="12">
                            <a-form-model-item label="个数" prop="count">
                                <a-input-number style="width: 100%;" v-model="couponForm.count"
                                                :min="1"></a-input-number>
                                <span class="formTip">优惠券创建后，发行量只能增加不能减少，请谨慎设置。</span>

                            </a-form-model-item>
                        </a-col>

                    </a-row>

                    <a-row :gutter="[24,0]">
                        <a-col :span="12">
                            <a-form-model-item label="减免条件" prop="what">
                                <a-select v-model="couponForm.what" placeholder="减免条件">
                                    <a-select-option value="1">
                                        满减
                                    </a-select-option>
                                    <a-select-option value="2">
                                        立减
                                    </a-select-option>
                                </a-select>
                            </a-form-model-item>
                        </a-col>
                        <a-col :span="12" v-if="couponForm.what==='1'">
                            <a-form-model-item label="满减最低消费" prop="min">
                                <a-input-number style="width: 100%;" v-model="couponForm.min" :min="0"
                                                step="0.01"></a-input-number>
                            </a-form-model-item>
                        </a-col>


                    </a-row>
                    <a-row :gutter="[24,0]">
                        <a-col :span="12">
                            <a-form-model-item label="优惠期限类型" prop="useType">
                                <a-select v-model="couponForm.useType" placeholder="优惠期限类型">
                                    <a-select-option value="1">
                                        时间范围内使用
                                    </a-select-option>
                                    <a-select-option value="2">
                                        领取后N日使用
                                    </a-select-option>
                                </a-select>
                            </a-form-model-item>
                        </a-col>
                        <a-col :span="12" v-show="couponForm.useType==='2'">
                            <a-form-model-item label="限时期限(天)" prop="limit">
                                <a-input-number style="width: 100%;" v-model="couponForm.limit"
                                                :min="0"></a-input-number>
                            </a-form-model-item>
                        </a-col>


                    </a-row>

                    <a-row :gutter="[24,0]">
                        <a-col :span="12">
                            <a-form-model-item label="开始时间" required prop="startTime">
                                <a-date-picker
                                        v-model="couponForm.startTime"
                                        show-time
                                        type="date"
                                        placeholder="选择开始时间"
                                        style="width: 100%;"
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col :span="12">
                            <a-form-model-item label="结束时间" required prop="endTime">
                                <a-date-picker
                                        v-model="couponForm.endTime"
                                        show-time
                                        type="date"
                                        placeholder="选择结束时间"
                                        style="width: 100%;"
                                />
                            </a-form-model-item>
                        </a-col>
                    </a-row>
                    <a-row :gutter="[24,-2]">
                        <a-col :span="8">
                            <a-form-model-item label="适用范围" prop="where">
                                <a-select v-model="couponForm.where" placeholder="请选择使用群体">
                                    <a-select-option value="1">
                                        单品优惠
                                    </a-select-option>
                                    <a-select-option value="2">
                                        固定商品
                                    </a-select-option>
                                    <a-select-option value="3">
                                        全店铺使用
                                    </a-select-option>
                                </a-select>
                            </a-form-model-item>
                        </a-col>

                    </a-row>
                    <a-row :gutter="[24,2]">

                        <a-col :span="24" v-show="couponForm.where==='1'||couponForm.where==='2'">
                            优惠商品：
                            <a-input-search v-model="goodsInput.key" @change="fetchGoods"></a-input-search>
                            <!--一定要指定rowKey,否则选择行会出错-->
                            <a-table
                                    rowKey="id"
                                    :row-selection="goodsRowSelection"
                                    :pagination="goodsPagination"
                                    size="middle" :columns="goodsColumns" :data-source="goodsData"
                                    :scroll="{ x: 800, y: 500 }">
                            </a-table>

                        </a-col>
                        <a-col v-show="false">
                            <a-form-model-item prop="goodsId">
                                <a-input v-model="couponForm.goodsId"></a-input>
                            </a-form-model-item>
                        </a-col>
                    </a-row>
                    <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
                        <a-button type="primary" @click="submitForm('couponForm')">
                            提 交
                        </a-button>
                        <a-button style="margin-left: 10px" @click="resetForm('couponForm')">
                            重 置
                        </a-button>
                    </a-form-model-item>

                </a-form-model>
            </a-card>
        </div>

    </div>
</template>

<script>

    const goodsColumns = [
        {title: '商品名', dataIndex: 'name', width: 200},
    ]
    const columns = [
        {title: '序号', dataIndex: 'id', key: 'id', width: 200, fixed: 'left'},

        {title: '优惠券名', width: 130, key: '', dataIndex: 'name'},

        {title: '描述', dataIndex: 'desc', width: 150, key: ''},
        {title: '发行量', dataIndex: 'count', key: '', width: 180},
        {title: '剩余张数', dataIndex: 'stock', key: '', width: 180},
        {title: '领取数', dataIndex: 'takeCount', key: '', width: 180},
        {title: '适用数', dataIndex: 'used', key: '', width: 180},
        {title: '使用群体', dataIndex: 'who', width: 150, key: '', scopedSlots: {customRender: "who"}},
        {
            title: '领取方式', dataIndex: 'how', width: 180, key: '', customRender: function (text) {
                if (text == 1) {
                    return "手动领取";
                } else if (text == 2) {
                    return "系统发放";
                } else {
                    return text;
                }
            }
        },
        {
            title: '使用范围', dataIndex: 'where', width: 100, key: '', customRender: function (text) {
                //范围：1. 单品优惠 2.指定商品 3.全店铺使用 4.专区 5. 全场    『1、2、3用于店铺优惠券，4和5用于系统优惠券』
                if (text == 1) {
                    return "单品优惠";
                } else if (text == 2) {
                    return "固定商品";
                } else if (text == 3) {
                    return "全店铺使用";
                } else {
                    return '未知范围';
                }
            }
        },

        {title: '减免方式', dataIndex: 'what', width: 60, key: '', scopedSlots: {customRender: "what"}},
        {title: '优惠期限类型', dataIndex: 'useType', width: 150, key: '', scopedSlots: {customRender: "use_type"}},
        {title: '类型', dataIndex: 'type', width: 150, key: '', scopedSlots: {customRender: "type"}},
        {title: '开始时间', dataIndex: 'startTime', key: '', width: 180, scopedSlots: {customRender: "startTime"}},
        {title: '结束时间', dataIndex: 'endTime', key: '', width: 180, scopedSlots: {customRender: "endTime"}},
        {title: '最低消费(元)', dataIndex: 'min', key: '', width: 180},
        {title: '优惠额度（元）', dataIndex: 'discountPrice', key: '', width: 180},

        {title: '限时优惠期限(天)', dataIndex: 'limit', key: '', width: 180, scopedSlots: {customRender: "limit"}},
        {title: '创建时间', dataIndex: 'createTime', key: '', width: 180, scopedSlots: {customRender: "createTime"}},
        {title: '状态', dataIndex: 'deleted', width: 60, key: '', scopedSlots: {customRender: "status"}},

        {
            title: '操作',
            key: 'operation',
            fixed: 'right',
            width: 270,
            scopedSlots: {customRender: 'action'},
        },
    ];

    import couponApi from "../../../api/info/couponApi";
    import goodsApi from "../../../api/goods/goodsApi";


    export default {
        inject: ["reload"],

        name: "couponMS",
        data() {
            //校验结束时间
            let checkEndTime = (rule, value, callback) => {

                if (!value) {
                    return callback(new Error('请输入结束时间'));
                }
                if (value <= this.couponForm.startTime) {
                    return callback(new Error('结束时间应晚于开始时间'));
                }
                if (this.couponForm.useType === 2 && (value.diff(this.couponForm.startTime, 'hours') / 24) <= this.couponForm.limit) {
                    return callback(new Error('期限应至少大于限时天数'));
                }
                callback()

            };
            let checkDiscountPrice = (rule, value, callback) => {

                if (!value) {
                    if (value <= 0) {
                        return callback(new Error('面额应大于0'));

                    }
                    return callback(new Error('请输入优惠面额'));
                }
                if (value > 1000) {
                    return callback(new Error('面额不能超过1000'));
                }
                if (value === 1 || value === 2 || value === 3 || value % 5 === 0) {
                    callback()
                } else {
                    return callback(new Error('请输入1/2/3/5及5的整数倍金额，面额不得超过1000元'));
                }

            };
            let checkCount = (rule, value, callback) => {

                if (!value) {
                    console.log(value)
                    return callback(new Error('请输入发行量'));
                }
                if (value < this.record.count) {
                    return callback(new Error('发行量应大于旧发行量'));
                }
                callback()


            };

            let checkStartTime = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('请输入开始时间'));
                }
                if (((value.diff(this.$moment.now(), "hours")) / 24) > 60) {
                    return callback(new Error('最长只能提前60天创建'));
                }
                console.log(this.couponForm.useType)
                if (this.couponForm.useType === 2 && (this.couponForm.endTime.diff(value, 'hours') / 24) <= this.couponForm.limit) {
                    this.couponForm.endTime = undefined;
                }
                callback()

            };
            let checkLimit = (rule, value, callback) => {

                if (this.couponForm.useType === 2 && (this.couponForm.endTime.diff(this.couponForm.startTime, 'hours') / 24) <= value) {
                    this.couponForm.endTime = undefined;
                }
                callback()


            };
            return {
                shopId: -1,
                searchItems: [
                    {
                        key: "status",
                        name: "状态",
                        options: [{"text": "全部", "value": '-1'}, {"text": "使用中", "value": '0'}, {
                            "text": "已删除",
                            "value": '1'
                        }],
                    },
                    {
                        key: "where",
                        name: "使用范围",
                        options: [
                            {"text": "全部", "value": '-1'},
                            {"text": "单品优惠", "value": '1'},
                            {"text": "固定商品", "value": '2'},
                            {"text": "全店铺使用", "value": '3'}],
                    },
                    {
                        key: "what",
                        name: "减免方式",
                        options: [{"text": "全部", "value": '-1'}, {"text": "满减", "value": '1'}, {
                            "text": "立减",
                            "value": '2'
                        }],
                    },
                    {
                        key: "useType",
                        name: "期限类型",
                        options: [{"text": "全部", "value": '-1'}, {"text": "指定期限", "value": '1'}, {
                            "text": "限时使用",
                            "value": '2'
                        }],
                    }
                ],
                pageSizeOptions: ['3', '5', '10', '20', '30'],
                goodsPageSizeOptions: ['3', '5', '10', '20', '30'],
                pageMap: {
                    current: 1,
                    pageSize: 5,
                    total: 0
                },
                columns,
                tableData: [],
                searchMap: {
                    status: "-1",
                    where: "-1",
                    what: "-1",
                    useType: "-1"
                },
                moment: this.$moment,
                //表单开始
                formVisible: false,
                drawerVisible: false,
                record: {},//当前编辑的优惠券
                couponForm: {
                    id: null,
                    name: '',
                    desc: '',
                    who: '1',//默认 1通用券
                    how: '1',//默认 1
                    where: '3',
                    type: '1',
                    what: '1',
                    useType: '1',
                    used: 0,
                    takeCount: 0,
                    startTime: this.$moment(),
                    endTime: undefined,
                    min: 0.00,
                    count: 1,
                    limit: 0,
                    discountPrice: 0.00,
                    goodsId: "",
                    shopId: this.shopId,

                },
                couponFormRules: {
                    discountPrice: [
                        {required: true, message: '请输入优惠面额', trigger: 'blur'}, {
                            validator: checkDiscountPrice,
                            trigger: 'blur'
                        }
                    ],
                    count: [
                        {required: true, message: '请输入发行量', trigger: 'blur'}, {
                            validator: checkCount,
                            trigger: 'blur'
                        }
                    ],

                    name: [
                        {required: true, message: '请输入优惠券名称', trigger: 'blur'},
                    ],
                    desc: [
                        {required: true, message: '请输入描述', trigger: 'blur'},
                    ],
                    startTime: [
                        {required: true, message: '请选择开始时间', trigger: 'blur'}, {
                            validator: checkStartTime,
                            trigger: 'change'
                        }
                    ],
                    endTime: [
                        {required: true, message: '请选择结束时间', trigger: 'blur'}, {
                            validator: checkEndTime,
                            trigger: 'change'
                        }
                    ],

                    limit: [
                        {required: false, message: '请输入限时期限', trigger: 'blur'}, {
                            validator: checkLimit,
                            trigger: 'change'
                        }
                    ]


                },
                //商品table
                goodsColumns,
                goodsData: [],
                goodsInput: {
                    key: ""
                },
                goodsRowSelection: {
                    selectedRowKeys: [],
                    onChange: this.onGoodsSelect,
                },
                goodsPagination: {
                    onChange: (value) => {
                        this.goodsPagination.current = value;
                        this.fetchGoods();
                    },
                    current: 1,
                    total: 0,
                    showTotal: total => `共 ${this.goodsPagination.total} 条数据`,
                    pageSize: 5,
                    showSizeChanger: true,
                    pageSizeOptions: ['3', '5', '10', '20', '30'],
                    onShowSizeChange: (current, pageSize) => {
                        this.goodsPagination.pageSize = pageSize;
                        this.goodsPagination.current = current;
                        this.fetchGoods()
                    }
                },//商品分页配置
                editFlag: false, //编辑标志 如果为true 则对where的监听不删除goodsId


            }
        },
        created() {
            this.fetchCouponData();
        },
        watch: {
            searchMap: {
                deep: true,
                handler: function () {
                    this.fetchCouponData()
                }
            },
            "couponForm.where": {
                handler: function (val) {
                    if (!this.editFlag) {
                        this.goodsRowSelection = {
                            selectedRowKeys: [],
                            onChange: this.onGoodsSelect,
                        }
                        this.couponForm.goodsId = ""
                    } else {

                        this.editFlag = false

                    }
                }
            },
        },
        methods: {
            deleteCoupon(record, deleted) {
                couponApi.updateDeleted(record.id, deleted).then(resp => {
                    if (resp.data.flag) {
                        this.$message.success(resp.data.message)
                        this.fetchCouponData()
                    }
                })
            },
            addCoupon(record) {
                this.formVisible = true;
                this.resetForm('couponForm')
                if (record) {
                    console.log(record)
                    this.editFlag = true;


                    this.couponForm = {
                        id: record.id,
                        name: record.name,
                        desc: record.desc,
                        who: record.who + '',//默认 1通用券
                        how: record.how + '',//默认 1
                        where: record.where + '',
                        type: record.type + '',
                        what: record.what + '',
                        useType: record.useType + '',
                        startTime: this.$moment(record.startTime),
                        endTime: this.$moment(record.endTime),
                        min: record.min,
                        count: record.count,
                        used: record.used,
                        takeCount: record.takeCount,
                        limit: record.limit,
                        discountPrice: record.discountPrice,
                        goodsId: JSON.stringify(record.goodsId),
                        shopId: record.shopId,
                    }
                    console.log(this.couponForm.goodsId)
                    Object.assign(this.record, this.couponForm)

                    if (record.where === 1 || record.where === 2) {
                        let checked = record.goodsId
                        console.log(checked)

                        this.goodsRowSelection = {
                            selectedRowKeys: checked,
                            onChange: this.onGoodsSelect,
                            getCheckboxProps: record => {
                                return {
                                    props: {
                                        // record为当前行数据    逻辑是 record.goodsId != null 的行默认勾选（条件）
                                        defaultChecked: checked.includes(record.id)
                                    }
                                };
                            },
                        }
                    } else {
                        this.goodsRowSelection = {
                            selectedRowKeys: [],
                            onChange: this.onGoodsSelect,
                        }
                    }
                } else {
                    this.record = {}
                    this.goodsRowSelection = {
                        selectedRowKeys: [],
                        onChange: this.onGoodsSelect,
                    }
                    console.log(this.goodsRowSelection.selectedRowKeys)
                }

            },
            submitForm(formName) {

                this.$refs[formName].validate(valid => {

                    if (valid) {
                        if (this.couponForm.where !== '3' && this.couponForm.goodsId === "") {
                            this.$message.warning("请选择参加优惠的商品")
                            return;
                        }
                        if (this.couponForm.where === '2') {
                            let goodIdList = JSON.parse(this.couponForm.goodsId)
                            if (goodIdList.length > 100) {
                                this.$message.warning("单个优惠券最多关联100个商品")
                                return;
                            }
                        }

                        let data = {}
                        Object.assign(data, this.couponForm)
                        data.goodsId = !data.goodsId || data.goodsId === "" ? [] : JSON.parse(data.goodsId)
                        data.startTime = data.startTime.format("YYYY-MM-DD HH:mm:ss")
                        data.endTime = data.endTime.format("YYYY-MM-DD HH:mm:ss")
                        if (this.couponForm.id) {
                            //修改
                            couponApi.update(data).then(resp => {
                                if (resp.data.flag) {
                                    this.$message.success(resp.data.message);
                                    this.reload()
                                }
                            })
                        } else {
                            couponApi.add(data).then(resp => {
                                if (resp.data.flag) {
                                    this.$message.success(resp.data.message);
                                    this.reload()

                                }
                            })
                        }

                    } else {
                        console.log("表单error")
                        return false;
                    }
                });
            },
            resetForm(formName) {

                this.$refs[formName].resetFields();
            },
            fetchGoods() {
                goodsApi.shopGoods(this.shopId ? this.shopId : null, this.goodsInput.key, this.goodsPagination.current, this.goodsPagination.pageSize).then(resp => {
                    if (resp.data.flag) {
                        this.goodsData = resp.data.data.rows;
                        this.goodsPagination.total = resp.data.data.total;
                    }
                })
            },
            fetchCouponData() {
                couponApi.shopCouponData(this.searchMap, this.pageMap.current, this.pageMap.pageSize).then(resp => {
                    if (resp.data.flag) {
                        this.tableData = resp.data.data.rows;
                        if (this.tableData.length > 0) {
                            this.shopId = this.tableData[0].shopId
                        }
                        console.log(this.tableData)
                        this.pageMap.total = resp.data.data.total;
                        if (this.goodsData.length > 0) {
                            return;
                        }
                        this.fetchGoods();

                    }
                })
            },


            pageChange(value) {
                this.pageMap.current = value;
                this.fetchCouponData();
            },

            /**
             * 每页大小改变的回调
             * */
            onShowSizeChange(current, pageSize) {
                this.pageMap.pageSize = pageSize;
                this.pageMap.current = current;
                this.fetchCouponData();
            },


            onGoodsSelect(selectedRowKeys) {
                let keys = []
                if (this.couponForm.where === '1') {
                    if (selectedRowKeys.length > 2) { //全选了
                        this.goodsRowSelection.selectedRowKeys = selectedRowKeys = [0]
                    } else {

                        this.goodsRowSelection.selectedRowKeys = selectedRowKeys.filter(item => !this.goodsRowSelection.selectedRowKeys.includes(item))
                    }
                } else {
                    if (selectedRowKeys.length > 100) {
                        this.$message.warning("单个优惠券最多关联100个商品")
                        return;
                    }
                    this.goodsRowSelection.selectedRowKeys = selectedRowKeys

                }
                this.couponForm.goodsId = JSON.stringify(this.goodsRowSelection.selectedRowKeys)
            },


        }
    }
</script>

<style scoped>

    .formTip {
        font-size: 9px;
        color: #999999;
    }
</style>